// 获取cookie、
export function getCookie (name) {
  if (document.cookie.length > 0) {
    var start = document.cookie.indexOf(name + '=')
    if (start !== -1) {
      start = start + name.length + 1
      var end = document.cookie.indexOf(';', start)
      if (end === -1) end = document.cookie.length
      return decodeURI(document.cookie.substring(start, end))
    }
  }
}

export function setCookie (name, value, expiredays) {
  var exp = new Date()
  exp.setTime(exp.getTime() + expiredays * 24 * 60 * 60 * 1000)
  document.cookie = name + '=' + encodeURI(value) + ((expiredays == null) ? '' : ';expires=' + exp.toGMTString())
}

// 删除cookie
export function delCookie (name) {
  var exp = new Date()
  exp.setTime(exp.getTime() - 1)
  var cval = getCookie(name)
  if (cval != null) {
    document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString()
  }
}
